/*----------------------------------------------------------
* FILE: HibernateDaoImpl.java
* LOGICAL NAME: HibernateDaoImpl
* PRODUCT: bila-framework
*----------------------------------------------------------
* MODIFICATIONS
* DATE Sep 17, 2011
* AUTHOR wjuarez
*----------------------------------------------------------
*/

package bila.framework.dao.hibernate.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Query;

import bila.framework.dao.hibernate.HibernateDao;

/**
 * @author WJuarez
 * <b>Created by </b>wjuarez
 * <b>for</b> bila-framework
 * <b>package</b> bila.framework.dao.hibernate.impl
 * <b>on</b> Sep 17, 2011 2:26:47 PM
 * <b>Purpose</b> 
 * <p>
 *		Implementacion de DAO utilizando framework Hibernate
 * </p>
 */
public class HibernateDaoImpl<Model, ModelId extends Serializable> extends HibernateDaoFinderImpl<Model, ModelId> implements HibernateDao<Model, ModelId> {

	public HibernateDaoImpl(Class<Model> clazz) {
		super(clazz);
	}

	/*
	 * (non-Javadoc)
	 * @see bila.framework.dao.Dao#save(java.lang.Object)
	 */
	public void save(Model model) throws Exception{
		getHibernateTemplate().save(model);
	}

	/*
	 * (non-Javadoc)
	 * @see bila.framework.dao.Dao#update(java.lang.Object)
	 */
	public void update(Model model) throws Exception{
		getHibernateTemplate().update(model);
	}

	/*
	 * (non-Javadoc)
	 * @see bila.framework.dao.Dao#delete(java.lang.Object)
	 */
	public void delete(Model model) throws Exception{
		getHibernateTemplate().delete(model);
	}

	/*
	 * (non-Javadoc)
	 * @see bila.framework.dao.hibernate.HibernateDao#saveOrUpdate(java.lang.Object)
	 */
	public void saveOrUpdate(Model model) throws Exception{
		getHibernateTemplate().saveOrUpdate(model);
	}

	/*
	 * (non-Javadoc)
	 * @see bila.framework.dao.hibernate.HibernateDao#executeDml(java.lang.String, java.lang.Object[])
	 */
	public void executeDml(String hql, Object[] params) throws Exception{
		Query query = getSession().createQuery(hql);
		for (int i = 0; i < params.length; i++)
			query.setParameter(i, params[i]);
		query.executeUpdate();
	}

	/*
	 * (non-Javadoc)
	 * @see bila.framework.dao.Dao#saveOrUpdateList(java.util.List)
	 */
	public void saveOrUpdateList(List<Model> list) throws Exception{
		getHibernateTemplate().saveOrUpdateAll(list);
	}

	/*
	 * (non-Javadoc)
	 * @see bila.framework.dao.Dao#deleteList(java.util.List)
	 */
	public void deleteList(List<Model> list) throws Exception{
		getHibernateTemplate().deleteAll(list);
	}
	

}
